package com.study.common.utils;

/**
 * 电话号码脱敏
 */
public class PhoneUtil {


    /**
     * 输入电话号码，将其进行脱敏
     * @param phone
     * @return
     */
    public static String numberChange(String phone) {

        //先分别获取号码的前三位和后四位
        String prefix = phone.substring(0,3);

        String suffix = phone.substring(phone.length() - 4);

        //替换中间数字位星号
        StringBuilder builder = new StringBuilder();
        builder.append(prefix);

        for (int i = 3; i < phone.length() - 4; i++) {
            builder.append("*");
        }
        builder.append(suffix);

        return builder.toString();
    }


}
